import { createRouter, createWebHashHistory } from 'vue-router'
import type { Router, RouteRecordRaw } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const router: Router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      name: 'main',
      component: () => import('@/views/main.vue'),
      redirect: { name: 'example1' },
      children: [
        {
          path: 'example1',
          name: 'example1',
          meta: { desc: '加载高德底图' },
          component: () => import('@/views/page/example1.vue')
        },
        {
          path: 'example2',
          name: 'example2',
          meta: { desc: '加载天地图' },
          component: () => import('@/views/page/example2.vue')
        },
        {
          path: 'example3',
          name: 'example3',
          meta: { desc: '基础控件' },
          component: () => import('@/views/page/example3.vue')
        },
        {
          path: 'example4',
          name: 'example4',
          meta: { desc: '地图动画' },
          component: () => import('@/views/page/example4.vue')
        },
        {
          path: 'example5',
          name: 'example5',
          meta: { desc: '添加点/线/多边形/圆/popup' },
          component: () => import('@/views/page/example5.vue')
        },
        {
          path: 'example6',
          name: 'example6',
          meta: { desc: '沿轨迹移动' },
          component: () => import('@/views/page/example6.vue')
        },
        {
          path: 'example7',
          name: 'example7',
          meta: { desc: '热力图显示/地图导出、打印' },
          component: () => import('@/views/page/example7.vue')
        },
        {
          path: 'example8',
          name: 'example8',
          meta: { desc: '加载海量数据' },
          component: () => import('@/views/page/example8.vue')
        },
        {
          path: 'example9',
          name: 'example9',
          meta: { desc: '自由绘制' },
          component: () => import('@/views/page/example9.vue')
        },
        {
          path: 'example10',
          name: 'example10',
          meta: { desc: '绘制规则图形' },
          component: () => import('@/views/page/example10.vue')
        },
        {
          path: 'example11',
          name: 'example11',
          meta: { desc: '测量距离/面积' },
          component: () => import('@/views/page/example11.vue')
        },
        {
          path: 'example12',
          name: 'example12',
          meta: { desc: '线段箭头' },
          component: () => import('@/views/page/example12.vue')
        },
        {
          path: 'example13',
          name: 'example13',
          meta: { desc: 'geo行政区绘制' },
          component: () => import('@/views/page/example13.vue')
        },
        {
          path: 'example14',
          name: 'example14',
          meta: { desc: '聚合图' },
          component: () => import('@/views/page/example14.vue')
        },
        {
          path: 'example15',
          name: 'example15',
          meta: { desc: '动态切换矢量/影像/地形' },
          component: () => import('@/views/page/example15.vue')
        }
      ]
    }
  ] as RouteRecordRaw[]
})

router.beforeEach(() => {
  NProgress.start()
})

NProgress.configure({ showSpinner: false });

router.afterEach(() => {
  NProgress.done()
})

export default router